// #include <cstdio>
// #include <iostream>
// #include <ctime>
#include "HCNetSDK.h"
#include <highgui.h>
#include <cv.h>
#include <stdio.h>
#include <stdlib.h>
// #include <opencv2/opencv.hpp>
using namespace std;

char* Jpeg;
NET_DVR_JPEGPARA *JpegPara;

char* get_Jpeg_Capture()
{
    // 初始化
	NET_DVR_Init();
	//设置连接时间与重连时间
	NET_DVR_SetConnectTime(2000, 1);
	NET_DVR_SetReconnect(10000, true);
    // 注册设备
	LONG lUserID;
	NET_DVR_DEVICEINFO_V30 struDeviceInfo;
	lUserID = NET_DVR_Login_V30("192.168.0.71", 8000, "admin", "12345", &struDeviceInfo);
	if (lUserID < 0)
	{
		printf("Login error, %d\n", NET_DVR_GetLastError());
		NET_DVR_Cleanup();
	}
    //定义JPEG图像质量
	JpegPara = (NET_DVR_JPEGPARA *)malloc(sizeof(NET_DVR_JPEGPARA));
	JpegPara->wPicQuality = 0;
	JpegPara->wPicSize = 9;

    Jpeg = (char*)malloc(200*1024);
	DWORD len = 200*1024;
	LPDWORD Ret = 0;
			
	if(!NET_DVR_SetCapturePictureMode(BMP_MODE))
	{
		// cout<<"Set Capture Picture Mode error!"<<endl;
		// cout<<"The error code is "<<NET_DVR_GetLastError()<<endl;
	}
    
	bool capture = NET_DVR_CaptureJPEGPicture_NEW(lUserID,1,JpegPara,Jpeg,len,Ret);
	if(!capture)
	{
		printf("Error: NET_DVR_CaptureJPEGPicture_NEW = %d", NET_DVR_GetLastError());	
	}
    return Jpeg;
}
void freeJpeg(){
	free(Jpeg);
	free(JpegPara);
}